package com.shadow.repository;

import com.mysema.query.types.OrderSpecifier;
import com.mysema.query.types.Predicate;
import com.mysema.query.types.expr.NumberExpression;
import com.mysema.query.types.path.EntityPathBase;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.NoRepositoryBean;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

@NoRepositoryBean
public interface MyCustomRepository<T, ID extends Serializable> extends
        JpaRepository<T, ID> {
    List<T> queryDsl(EntityPathBase<T> entityToSelect, Predicate... o);

    List<T> queryDsl(EntityPathBase<T> entityToSelect, int start, int limit, Predicate... o);

    T querySingle(EntityPathBase<T> entityToSelect, Predicate... o);

    T querySingle(EntityPathBase<T> entityToSelect, OrderSpecifier<?> order,
                  Predicate... o);

    List<T> queryDslWithOrder(EntityPathBase<T> entityToSelect,
                              OrderSpecifier<?> order, Predicate... o);

    List<T> queryDslWithOrderAndLimit(EntityPathBase<T> entityToSelect,
                                      OrderSpecifier<?> order, int limitNum, Predicate... o);

    List<T> queryDslWithOrderAndLimit(EntityPathBase<T> entityToSelect,
                                      OrderSpecifier<?> order, int limitNum);

    List<T> queryDslWithOrder(EntityPathBase<T> entityToSelect,
                              OrderSpecifier<?> order, int offset, int limitNum);

    BigDecimal querySumResult(EntityPathBase<T> entityToSelect,
                              NumberExpression<BigDecimal> numberExpression, Predicate... o);

    public void persist(Object object);

    public T merge(T entity);

    /**
     * 按照JPQL表达式查询字段
     *
     * @param jpql
     * @return
     */
    public List<Object[]> queryByJPQL(String jpql, int startIndex, int size);

    public Long queryCountByJPQL(String jpql);


}

